﻿namespace ImageProcessing.Forms
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using ImageProcessing.Properties;

    /// <summary>
    /// effects form for eefcts on image
    /// </summary>
    public partial class Effects : Form
    {
        /// <summary>
        /// image 1
        /// </summary>
        private DImage image1 = new DImage();

        /// <summary>
        /// image 2
        /// </summary>
        private DImage image2 = new DImage();

        /// <summary>
        /// current action effect
        /// </summary>
        private EffectsAction currentAction;

        /// <summary>
        /// Initializes a new instance of the <see cref="Effects"/> class.
        /// </summary>
        public Effects()
        {
            this.InitializeComponent();
            this.pictureBox1.Image = Properties.Resources.flowers;
            if (Main.ImageList.Count == 0)
            {
                return;
            }

            foreach (DImage img in Main.ImageList)
            {
                this.CmbImages.Items.Add(img.Name);
            }

            this.CmbImages.SelectedIndex = 0;

           this.image1.ImageStructArray = Main.ImageList[this.CmbImages.SelectedIndex].ImageStructArray;
           image1.Height = image1.ImageStructArray.GetLength(0);
           image1.Width = image1.ImageStructArray.GetLength(1);

            this.PcbOldImage.Image = Operations.DisplayMatrix(Main.ImageList[this.CmbImages.SelectedIndex].ImageStructArray);

        }

        /// <summary>
        /// Handles the SelectedIndexChanged event of the CmbImages control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void CmbImages_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.image1.ImageStructArray = Main.ImageList[this.CmbImages.SelectedIndex].ImageStructArray;
            image1.Height = image1.ImageStructArray.GetLength(0);
            image1.Width = image1.ImageStructArray.GetLength(1);
            this.PcbOldImage.Image = Operations.DisplayMatrix(Main.ImageList[this.CmbImages.SelectedIndex].ImageStructArray);

        }

        /// <summary>
        /// Handles the Click event of the arrowsToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void ArrowsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.currentAction = EffectsAction.Arrows;
            this.P1.Image = Properties.Resources.arrow1test;
            this.P2.Image = Properties.Resources.arrow2test;
            this.P3.Image = Properties.Resources.arrow3test;
            this.P4.Image = Properties.Resources.arrow4test;
            this.P5.Image = Properties.Resources.arrow5test;
            this.P6.Image = Properties.Resources.arrow6test;
        }

        /// <summary>
        /// Handles the MouseClick event of the P control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        private void P_MouseClick(object sender, MouseEventArgs e)
        {
            PictureBox p = (PictureBox)sender;
            if (p.BorderStyle == BorderStyle.Fixed3D)
            {
                p.BorderStyle = BorderStyle.None;
              //  this.PcbNewImage.Image = this.PcbOldImage.Image;
            //    return;
            }
            else
            {
                p.BorderStyle = BorderStyle.Fixed3D;
            }

            string num = p.Name;
            switch (this.currentAction)
            {
                case EffectsAction.Arrows:
                    this.ArrowsEffects(p, num[1]);
                    break;
                case EffectsAction.Brush:
                    this.BrushEffects(p, num[1]);
                    break;
                case EffectsAction.Edges:
                    this.EdgesEffects(p, num[1]);
                    break;
                case EffectsAction.Object:
                    this.ObjEffects(p, num[1]);
                    break;
                case EffectsAction.Art:
                    this.ArtEffect(p, num[1]);
                    break;
            }
        }

        /// <summary>
        /// Arts the effect.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <param name="num">The num.</param>
        private void ArtEffect(PictureBox p, char num)
        {
            Main.OperationName = "Art Effect";
            switch (num)
            {
                case '1':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.art1), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '2':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.art2), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '3':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.art3), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '4':
                   this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.art4), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '5':
                   this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.art5), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '6':
                  this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.art6), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
            }
        }

        /// <summary>
        /// Objs the effects.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <param name="num">The num.</param>
        private void ObjEffects(PictureBox p, char num)
        {
            Main.OperationName = "object Effect";
            
            switch (num)
            {
                case '1':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.obj1), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '2':
                    this.image2.ImageStructArray= CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.obj2), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '3':
                    this.image2.ImageStructArray= CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.obj3), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '4':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.obj4), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '5':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.obj5), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '6':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.obj6), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
            }
        }

        /// <summary>
        /// Arrowses the effects.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <param name="num">The num.</param>
        private void ArrowsEffects(PictureBox p, char num)
        {
            Main.OperationName = "Arrows Effect";
            switch (num)
            {
                case '1':
                    this.image2.ImageStructArray =CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.arrow1), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '2':
                    this.image2.ImageStructArray =CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.arrow2), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '3':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.arrow3), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '4':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.arrow4), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '5':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.arrow5), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '6':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.arrow6), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
            }
        }

        /// <summary>
        /// Brushes the effects.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <param name="num">The num.</param>
        private void BrushEffects(PictureBox p, char num)
        {
            Main.OperationName = "Bursh Effects";
            switch (num)
            {
                case '1':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.brush1), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '2':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.brush2), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '3':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.brush3), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '4':
                    this.image2.ImageStructArray= CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.brush4), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '5':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.brush5), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '6':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.brush6), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
            }
        }

        /// <summary>
        /// Edgeses the effects.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <param name="num">The num.</param>
        private void EdgesEffects(PictureBox p, char num)
        {
            Main.OperationName = "Edegs Effect";
            switch (num)
            {
                case '1':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.edge1), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '2':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.edge2), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '3':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.edge3), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '4':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.edge4), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '5':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.edge5), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
                case '6':
                    this.image2.ImageStructArray = CalcOperation.OrIamges(this.image1.ImageStructArray, ResizeImage.BicubicResize(this.image1.Width, this.image1.Height, Operations.ConvertBitmapToStructure(Properties.Resources.edge6), 2));
                    this.PcbNewImage.Image = Operations.DisplayMatrix(this.image2.ImageStructArray);
                    break;
            }
        }

        /// <summary>
        /// Handles the 1 event of the CmbImages_SelectedIndexChanged control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void CmbImages_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            this.image1.ImageStructArray= Main.ImageList[this.CmbImages.SelectedIndex].ImageStructArray;
            this.PcbOldImage.Image = Operations.DisplayMatrix(this.image1.ImageStructArray);
        }

        /// <summary>
        /// Handles the Click event of the BtnCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the BtnOk control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void BtnOk_Click(object sender, EventArgs e)
        {
            Main.ImageList[this.CmbImages.SelectedIndex].UpdateImage(this.image2.ImageStructArray);
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the brushToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void BrushToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.currentAction = EffectsAction.Brush;
            this.P1.Image = Properties.Resources.brush1test;
            this.P2.Image = Properties.Resources.brush2test;
            this.P3.Image = Properties.Resources.brush3test;
            this.P4.Image = Properties.Resources.brush4test;
            this.P5.Image = Properties.Resources.brush5test;
            this.P6.Image = Properties.Resources.brush6test;
        }

        /// <summary>
        /// Handles the Click event of the edgesToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void EdgesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.currentAction = EffectsAction.Edges;
            this.P1.Image = Properties.Resources.edge1test;
            this.P2.Image = Properties.Resources.edge2test;
            this.P3.Image = Properties.Resources.edge3test;
            this.P4.Image = Properties.Resources.edge4test;
            this.P5.Image = Properties.Resources.edge5test;
            this.P6.Image = Properties.Resources.edge6test;
        }

        /// <summary>
        /// Handles the Click event of the objectsToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void ObjectsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.currentAction = EffectsAction.Object;
            this.P1.Image = Properties.Resources.obj1test;
            this.P2.Image = Properties.Resources.obj2test;
            this.P3.Image = Properties.Resources.obj3test;
            this.P4.Image = Properties.Resources.obj4test;
            this.P5.Image = Properties.Resources.obj5test;
            this.P6.Image = Properties.Resources.obj6test;
        }

        /// <summary>
        /// Handles the Click event of the artToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void artToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.currentAction = EffectsAction.Art;
            this.P1.Image = Properties.Resources.art1test;
            this.P2.Image = Properties.Resources.art2test;
            this.P3.Image = Properties.Resources.art3test;
            this.P4.Image = Properties.Resources.art4test;
            this.P5.Image = Properties.Resources.art5test;
            this.P6.Image = Properties.Resources.art6test;
        }
    }
}
